Break tests with a small hash function perturbation #4559
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the reasons/motivation for this change?
Test failures due to hashing refactoring have uncovered
dfflibmap.ys
to fail to prove the first step base case in the firstequiv_opt
call. This PR demonstrates that it is sufficient to slightly change the hashing function to break that test. Famously, go lang standard library and abseil randomize hash functions to prevent users on depending on the ordering of items in unordered maps like dicts and sets. In Yosys, the DJB2 hash function hasn't been touched in 10 years. This draft PR will be closed when this problem is resolved and the hash function has a mechanism when it's randomized. Until then, it's a reproducer.There is no way to write an "incorrect" hash function that isn't meant to be cryptographic, since hash functions are only meant to be used for fast path handling of data. A
return 1;
hash function is just as valid as an actual hash function, though it make tests run for too long. Therefore this PR should never make correctness tests fail.Explain how this is achieved.
Every time you hash, xorshift the result, and xor with a fudge constant. For example, you can reproduce this with a fudge constant of 123456 or 42069, but not 3.